import {inject, observer} from 'mobx-react';
import {observable,action,toJS} from 'mobx';
import { Modal } from 'antd'
const confirm = Modal.confirm;

import { WeaLocaleProvider } from "ecCom";
const getLabel = WeaLocaleProvider.getLabel;

@inject('blogMyAttention')
@observer
class AttentionTool extends React.Component {
	constructor(props) {
		super(props);
		this.apply = this.apply.bind(this);
	}
	
	apply(event) {
		event.stopPropagation();
		let {attentionStatus, islower, userId, callback} = this.props;
		let _this = this
		if(attentionStatus == 1 || attentionStatus == 2) {
			confirm({
				title: getLabel('384420',"确认要取消关注吗？"),
				content: '',
				onOk (){
					_this.props.blogMyAttention.editAttention({attentionStatus, islower, userId}, callback);
				},
				onCancel() {},
			});
		} else {
            let type = this.props.blogMyAttention.status.type;
			_this.props.blogMyAttention.editAttention({attentionStatus, islower, userId,type}, callback);
		}
	}
	
	render() {
		/**
		 *
		 * attentionStatus
		 1表示单向关注，按钮显示 取消关注。
		 2表示双向关注，按钮显示 取消关注。
		 3表示没有关注关系，且不是上下级关系。 按钮显示 申请关注。
		 4表示没有关注关系，且不是上下级关系，且已发送申请。按钮显示 已发送申请。
		 5表示没有关注关系，且是上下级关系。按钮显示 添加关注。
		 isreceive==0,不允许申请关注
		 */
		let text=getLabel(26938,"取消关注");
		let func = this.apply;
		let {isreceive, attentionStatus} = this.props;
		let className = "icon-blog-CancelConcern";
		switch(this.props.attentionStatus) {
			case "3": text=getLabel('26941',"申请关注");className = "icon-blog-AddTo";break;
			case "4": text=getLabel(18659,"已申请");func = undefined;className = "icon-blog-AlreadyConcern";break;
			case "5": text=getLabel('26939',"添加关注");className = "icon-blog-AddTo";break;
			default: break;
		}
		return (
			(isreceive == '0' && attentionStatus == '3') 
			? <span />
			: <a className="tool" onClick={func}><span className={className} />{text}</a>
		);
	}
}

AttentionTool.propTypes = {
	attentionStatus: React.PropTypes.string,//当前关注状态
	userId: React.PropTypes.string,//人员id
	islower: React.PropTypes.string,//后台需要的参数
	callback: React.PropTypes.func//用户点击按钮、执行成功后的回调。
};

export default AttentionTool;